const Mock = require('mockjs')

const data = Mock.mock({
    'news|10': [{
        id: '@increment',
        name: '@string("gfdgazffscfgZZFddz",4,10)',
        addTime: '@datetime("yyyy-MM-dd HH:mm:ss")'
    }]
})

// var obj = {
//     code: 2000,
//     data: data.news
// }

// console.log(obj);

function searchNewByUserName(userName) {
    var searchRes = []
    data.news.forEach(element => {
        if (element.name == userName) {
            searchRes.push(element)
        }
    });
    return searchRes;
}

module.exports = [
    //getAllUser 
    {
        url: '/admin/getAllNew',
        type: 'get',
        response: config => {
            return {
                code: 20000,
                data: data.news
            }
        }
    },
    {
        url: '/admin/delNewById',
        type: 'post',
        response: config => {
            let { id } = config.query
            console.log(id);
            return {
                code: 20000,
                data: "success"
            }
        }
    },
    {
        url: '/admin/searchNewByName',
        type: 'post',
        response: config => {
            let { name } = config.query
            return {
                code: 20000,
                data: searchNewByUserName(name)
            }
        }
    },

]